package com.ttl.bc.master.shelf;

import hibernate.util.HibernateUtil;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import com.ttl.common.db.ADAO;

public class BCShelfDAO extends ADAO {
	
	@SuppressWarnings("unchecked")
	public List findAll() {
		List result = null;
		ArrayList al = new ArrayList();
		Session session = null;

		try {
			SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
			session = sessionFactory.openSession();
			
			session.beginTransaction();
			
			Query q = session.createQuery("FROM BCShelfBean ORDER BY code");
			result = q.list();			
						
			session.getTransaction().commit();						
			
		}catch(Exception e) {			
			System.out.println(e.toString());
		}finally {
			session.close();
		}
		
		if(result!=null && result.size()>0) {
			for (int i = 0; i < result.size(); i++) {
				BCShelfBean bean = (BCShelfBean)result.get(i);
				bean.setName(bean.getCode()+":"+bean.getName());
				al.add(bean);
			}
			result = al;
		}
		
		return result;
	}	
}
